﻿using System.Collections.Generic;
using WindowsPhoneMvp.Phone.State;
using WindowsPhoneEssentials.Storage;

namespace WindowsPhoneMvp.Mocks.Phone.State
{
    public class MockTransientState : IStorageProvider
    {
        public MockTransientState()
        {
            ResultState = new Dictionary<string, object>();    
        }

        public IDictionary<string,object> ResultState { get; set; }

        public void Save<T>(string key, T value) where T : class 
        {
            ResultState[key] = value;
        }

        public T Load<T>(string key) where T : class
        {
            object value;
            ResultState.TryGetValue(key, out value);
            return (T)value;
        }

        public bool Contains(string key)
        {
            return ResultState.ContainsKey(key);
        }

        public void Remove(string key)
        {
            if (ResultState.ContainsKey(key))
                ResultState.Remove(key);
        }
    }
}
